<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            任务名称：<input type="text" name="taskName"/>
                        </li>

                        <li>
                            任务状态：
                            <!--<input type="text" name="taskStatus"/>-->
                            <select name="taskStatus">
                                <option th:text="全部" value=""></option>
                                <option th:text="新增" value="新增"></option>
                                <option th:text="采集" value="采集"></option>
                                <option th:text="审核" value="审核"></option>
                                <option th:text="归档" value="归档"></option>
                            </select>
                        </li>

                        <li>
                            计划开始时间：<input type="date" name="pStartTime"/>
                        </li>

                        <!--<li>
                            计划结束时间：<input type="text" name="pEndTime"/>
                        </li>

                        <li>
                            实际开始时间：<input type="text" name="cStartTime"/>
                        </li>

                        <li>
                            实际结束时间：<input type="text" name="cEndTime"/>
                        </li>

                        <li>
                            变压器ID：<input type="text" name="byqId"/>
                        </li>

                        <li>
                            线路ID：<input type="text" name="lineId"/>
                        </li>

                        <li>
                            任务说明：<input type="text" name="taskNote"/>
                        </li>-->

                        <!--<li>-->
                            <!--任务分配时间：<input type="date" name="releaseTime"/>-->
                        <!--</li>-->

                        <!--<li>
                            采集人ID：<input type="text" name="useId"/>
                        </li>

                        <li>
                            任务创建/分配人ID：<input type="text" name="createId"/>
                        </li>

                        <li>
                            审核人ID：<input type="text" name="auditorId"/>
                        </li>-->

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="assets:pTask:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary btn-edit disabled" onclick="$.operate.editFull()"
               shiro:hasPermission="assets:pTask:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <!--<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()"-->
            <a class="btn btn-danger btn-del btn-del disabled" onclick="removeAllForTask()"
               shiro:hasPermission="assets:pTask:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <!--<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="assets:pTask:export">-->
                <!--<i class="fa fa-download"></i> 导出-->
            <!--</a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('assets:pTask:edit')}]];
    var removeFlag = [[${@permission.hasPermi('assets:pTask:remove')}]];
    var prefix = ctx + "assets/pTask";
    var line = null;
    var createLineUser = null;
    var byq = null;

    $(function () {

        $.post(ctx + "assets/iLine/getLineName", function (r) {
            line = r.iLines;
        });
        $.post(ctx + "assets/iLine/getCreateLineUserName", function (r) {
            createLineUser = r.userList;
        });
        $.post(ctx + "assets/bByq/getByqName", function (r) {
            byq = r.bByqList;
        });

        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            showSearch:false,		//是否显示检索信息
            showRefresh:false,		//是否显示刷新按钮
            showToggle:false,		//是否显示详细视图和列表视图的切换按钮
            showColumns:false,		//是否显示隐藏某列下拉框
            sortable:false,		//是否启用排序
            modalName: "采集任务",
//            showExport: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '任务ID',
                    visible: false
                },
                {
                    field: 'taskName',
                    title: '任务名称',
                    sortable: true
                },
                {
                    field: 'lineId',
                    title: '线路名称',
                    sortable: true,
                    formatter: function (value, row, index) {
//                        console.log("线路名称=="+JSON.stringify(row))
//                        for (index in value) {
//                            if (line[index].id == value)
//                                return line[index].name;
//                        }
                        return row.lineName;
                    }
                },
                {
                    field: 'byqId',
                    title: '变压器名称',
                    sortable: true,
                    formatter: function (value, row, index) {
                        for (index in byq) {
                            if (value == byq[index].id)
                                return byq[index].name;
                        }
                    }
                },
                {
                    field: 'taskNote',
                    title: '任务说明',
                    sortable: true
                },
                {
                    field: 'pStartTime',
                    title: '计划开始时间',
                    sortable: true,
                    formatter: function (value, row, index) {
                        var timess = row.pstartTime.substring(0,11);
//                        return timess!=null?new Date(value).Format('yyyy-MM-dd'):"";
                        return timess;
                    }
                },
                {
                    field: 'pEndTime',
                    title: '计划结束时间',
                    sortable: true,
                    formatter: function (value, row, index) {
                        var timess = row.pendTime.substring(0,11);
//                        return timess!=null?new Date(value).Format('yyyy-MM-dd'):"";
                        return timess;
                    }
                },
                {
                    field: 'cStartTime',
                    title: '实际开始时间',
                    sortable: true,
                    visible: false,
                    formatter: function (value, row, index) {
                        return value != null ? new Date(value).Format('yyyy-MM-dd') : "";
                    }
                },
                {
                    field: 'cEndTime',
                    title: '实际结束时间',
                    sortable: true,
                    visible: false,
                    formatter: function (value, row, index) {
                        return value != null ? new Date(value).Format('yyyy-MM-dd') : "";
                    }
                },


                {
                    field: 'useId',
                    title: '采集人',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return row.useName;
//                        for(index in value){
//                            if(createLineUser[index].userId == value)
//                                return createLineUser[index].userName;
//                        }
                    }
                },
                {
                    field: 'auditorId',
                    title: '审核人',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return row.useName;
                    }
                },
                {
                    field: 'createId',
                    title: '任务创建/分配人',
                    sortable: true,
                    visible: false,
                    formatter: function (value, row, index) {
                        return row.useName;
//                        for (index in value) {
//                            if (createLineUser[index].userId == value)
//                                return createLineUser[index].userName;
//                        }
                    }
                },
                {
                    field: 'taskStatus',
                    title: '任务状态',
                    sortable: true
                },
                {
                    field: 'releaseTime',
                    title: '任务分配时间',
                    sortable: true,
                    visible: false,
                    formatter: function (value, row, index) {
                        return value != null ? new Date(value).Format('yyyy-MM-dd hh:mm:ss') : "";
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
//                        if (row.taskStatus != "归档") {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.editFull(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
//                        }
                        if (row.taskStatus == "审核") {
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="file(\'' + row.id + '\')"><i class="fa fa-caret-square-o-right"></i>归档</a>');
                        } else if (row.taskStatus == "新增") {
                            actions.push('<a class="btn btn-success btn-xs ' + removeFlag + '" href="#" onclick="release(\'' + row.id + '\')"><i class="fa fa-exchange"></i>发布</a>');
                        } else if(row.taskStatus == "采集"){
                            actions.push('<a class="btn btn-success btn-xs ' + removeFlag + '" href="#" onclick="end(\'' + row.id + '\')"><i class="fa fa-exchange"></i>结束采集</a>');
                        }
                        actions.push('<a class="btn btn-success btn-xs ' + removeFlag + '" href="#" onclick="detail(\'' + row.id + '\',\'' + row.taskName + '\',\'' + row.lineId + '\')"><i class="fa fa-server"></i>详情</a>');
                        return actions.join('&nbsp');
                    }
                }]
        };
        $.table.init(options);
    });
    /**
     *    归档
     */
    function file(id) {

        $.get(prefix + "/file/" + id, function (r) {
            $.table.refresh();
        });
    }
    /**
     *    发布
     */
    function release(id) {

        $.get(prefix + "/release/" + id, function (r) {
            $.table.refresh();
        });
    }
    /**
     *    结束采集
     */
    function end(id) {

        $.get(prefix + "/end/" + id, function (r) {
            $.table.refresh();
        });
    }
    /**
     *    任务详情
     */
    function detail(id, taskName) {
//        var url = prefix + '/pTaskDetails/' + id;
        var url = prefix + '/pTaskMap/' + id;
        createMenuItem(url, taskName + "详情");
    }

    //  修改
    function editForTask() {
        var url = "/404.html";
        var rowsTaskStauts = $.table.selectColumns("taskStatus");
        if(rowsTaskStauts == "归档"){
            $.modal.alertWarning("归档后不能编辑");
            return;
        }
        if ($.common.isNotEmpty(id)) {
            url = $.table._option.updateUrl.replace("{id}", id);
        } else {
            var row = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
            url = $.table._option.updateUrl.replace("{id}", row);
        }
        $.modal.openFull("修改" + $.table._option.modalName, url);
    }


    //  删除
    function removeAllForTask() {
        var rowsId = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
        var rowsTaskStauts = $.table.selectColumns("taskStatus");
        console.log("删除获取信息=="+JSON.stringify(rowsTaskStauts));
        if (rowsId.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        if(rowsTaskStauts == "归档"){
            $.modal.alertWarning("归档后不能被删除");
            return;
        }
        $.modal.confirm("确认要删除选中的" + rowsId.length + "条数据吗?", function () {
            var url = $.table._option.removeUrl;
            var data = {"ids": rowsId.join()};
            $.operate.submit(url, "post", "json", data);
        });
    }

    /**
     *    日期格式化
     */
    Date.prototype.Format = function (fmt) {
        var o = {
            "M+": this.getMonth() + 1, //月份
            "d+": this.getDate(), //日
            "h+": this.getHours(), //小时
            "m+": this.getMinutes(), //分
            "s+": this.getSeconds(), //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds() //毫秒
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }

</script>
</body>
</html>